
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>从本地建立仓库 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="唐浩晋 <tanghaojin@outlook.com>; 陈璐; 高泽宇">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="本地与远程仓库的交互.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Git 使用规范手册
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../入门/">
            
                <a href="../入门/">
            
                    
                    入门
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../入门/Git简介.html">
            
                <a href="../入门/Git简介.html">
            
                    
                    Git 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../入门/Git安装.html">
            
                <a href="../入门/Git安装.html">
            
                    
                    Git 安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    基本操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="从本地建立仓库.html">
            
                <a href="从本地建立仓库.html">
            
                    
                    从本地建立仓库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="本地与远程仓库的交互.html">
            
                <a href="本地与远程仓库的交互.html">
            
                    
                    本地与远程仓库的交互
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../开发流程和规范.html">
            
                <a href="../开发流程和规范.html">
            
                    
                    开发流程和规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../进阶操作.html">
            
                <a href="../进阶操作.html">
            
                    
                    进阶操作
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >从本地建立仓库</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4ECE;&#x672C;&#x5730;&#x5EFA;&#x7ACB;&#x4ED3;&#x5E93;">&#x4ECE;&#x672C;&#x5730;&#x5EFA;&#x7ACB;&#x4ED3;&#x5E93;</h1>
<p>&#x672C;&#x8282;&#x5C06;&#x4ECB;&#x7ECD; Git &#x672C;&#x5730;&#x4ED3;&#x5E93;&#x7684;&#x5EFA;&#x7ACB;&#x548C;&#x57FA;&#x672C;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;. </p>
<h2 id="&#x521D;&#x59CB;&#x5316;">&#x521D;&#x59CB;&#x5316;</h2>
<pre><code class="lang-git">git init
</code></pre>
<p>&#x5728;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#x4E0B;&#x6267;&#x884C; <code>git init</code>, &#x5C31;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; git &#x7248;&#x672C;&#x5E93;. 
&#x6B64;&#x65F6; git &#x76F8;&#x5173;&#x4FE1;&#x606F;&#x5B58;&#x50A8;&#x5728; <code>.git</code> &#x76EE;&#x5F55;&#x4E2D;.</p>
<h2 id="&#x8BB0;&#x5F55;&#x66F4;&#x65B0;&#x5230;&#x4ED3;&#x5E93;">&#x8BB0;&#x5F55;&#x66F4;&#x65B0;&#x5230;&#x4ED3;&#x5E93;</h2>
<ul>
<li><code>git add &lt;pathspec&gt;</code>: &#x8DDF;&#x8E2A;&#x65B0;&#x6587;&#x4EF6;, &#x6682;&#x5B58;&#x5DF2;&#x4FEE;&#x6539;&#x7684;&#x6587;&#x4EF6;.
&#x8BE5;&#x547D;&#x4EE4;&#x4F1A;&#x5C06;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x76EE;&#x5F55; (&#x4EE5;&#x53CA;&#x5176;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x6587;&#x4EF6;) &#x6DFB;&#x52A0;&#x5230;&#x6682;&#x5B58;&#x533A; (stage) &#x4E2D;.</li>
<li><p><code>git commit [-m &lt;message&gt;]</code>: &#x5C06;&#x5F53;&#x524D;&#x6682;&#x5B58;&#x533A;&#x7684;&#x4FEE;&#x6539;&#x63D0;&#x4EA4;&#x81F3;&#x7248;&#x672C;&#x5E93;.
&#x8BE5;&#x547D;&#x4EE4;&#x4F1A;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x6587;&#x672C;&#x7F16;&#x8F91;&#x5668;&#x6765;&#x8F93;&#x5165;&#x63D0;&#x4EA4;&#x8BF4;&#x660E;.</p>
<ul>
<li><code>-m &lt;message&gt;</code>: &#x5C06; <code>message</code> &#x4F5C;&#x4E3A;&#x63D0;&#x4EA4;&#x8BF4;&#x660E;, &#x800C;&#x4E0D;&#x518D;&#x6253;&#x5F00;&#x6587;&#x672C;&#x7F16;&#x8F91;&#x5668;.</li>
</ul>
</li>
</ul>
<blockquote>
<p>[!TIP]&#x542F;&#x52A8;&#x7684;&#x7F16;&#x8F91;&#x5668;&#x662F;&#x901A;&#x8FC7; Shell &#x7684;&#x73AF;&#x5883;&#x53D8;&#x91CF; <code>EDITOR</code> &#x6307;&#x5B9A;&#x7684;&#xFF0C;&#x4E00;&#x822C;&#x9ED8;&#x8BA4;&#x4E3A; vim.
&#x5982;&#x679C;&#x60F3;&#x8981;&#x81EA;&#x5B9A;&#x4E49;&#x6253;&#x5F00;&#x7684;&#x6587;&#x672C;&#x7F16;&#x8F91;&#x5668;, &#x53EF;&#x4EE5;&#x4F7F;&#x7528;
<code>git config --global core.editor &lt;editor&gt;</code> &#x547D;&#x4EE4;&#x6765;&#x8BBE;&#x7F6E;.</p>
</blockquote>
<ul>
<li><p><code>git rm [--cached|-f] &lt;pathspec&gt;</code>: &#x5C06;&#x6587;&#x4EF6;&#x6216;&#x8DEF;&#x5F84;&#x4ECE; git &#x548C;&#x5DE5;&#x4F5C;&#x533A;&#x79FB;&#x9664;.</p>
<ul>
<li><code>--cached</code>: &#x4E0D;&#x8981;&#x5C06;&#x6587;&#x4EF6;&#x4ECE;&#x5DE5;&#x4F5C;&#x533A;&#x79FB;&#x9664;.</li>
<li><code>-f</code>: &#x5373;&#x4F7F;&#x6307;&#x5B9A;&#x7684;&#x8DEF;&#x5F84;&#x5B58;&#x5728;&#x6682;&#x5B58;&#x6216;&#x672A;&#x6682;&#x5B58;&#x7684;&#x66F4;&#x6539;, &#x4ECD;&#x7136;&#x6267;&#x884C;.</li>
</ul>
</li>
<li><code>git mv &lt;source&gt; &lt;target&gt;</code>: &#x5C06;&#x6587;&#x4EF6;&#x5728; git &#x4E2D;&#x79FB;&#x52A8;/&#x91CD;&#x547D;&#x540D;.
&#x8BE5;&#x64CD;&#x4F5C;&#x5B8C;&#x5168;&#x7B49;&#x4EF7;&#x4E8E;:</li>
</ul>
<pre><code class="lang-git">mv &lt;source&gt; &lt;target&gt;
git rm &lt;source&gt;
git add &lt;target&gt;
</code></pre>
<h2 id="&#x67E5;&#x770B;&#x4FE1;&#x606F;">&#x67E5;&#x770B;&#x4FE1;&#x606F;</h2>
<ul>
<li><p><code>git status</code>: &#x68C0;&#x67E5;&#x5F53;&#x524D;&#x6587;&#x4EF6;&#x72B6;&#x6001;. &#x8FD9;&#x4E9B;&#x72B6;&#x6001;&#x5305;&#x62EC;&#x4F46;&#x4E0D;&#x9650;&#x4E8E;:</p>
<ul>
<li>&#x4FEE;&#x6539;&#x8FC7;&#x4F46;&#x5C1A;&#x672A;&#x6682;&#x5B58;&#x7684;&#x6587;&#x4EF6;</li>
<li>&#x6682;&#x5B58;&#x8FC7;&#x4F46;&#x5C1A;&#x672A;&#x63D0;&#x4EA4;&#x7684;&#x6587;&#x4EF6;</li>
<li>&#x5C1A;&#x672A;&#x8DDF;&#x8E2A;&#x7684;&#x6587;&#x4EF6;</li>
<li>&#x65B0;&#x52A0;&#x5165;&#x6682;&#x5B58;&#x533A;&#x7684;&#x6587;&#x4EF6;</li>
<li>&#x4ECE;&#x6682;&#x5B58;&#x533A;&#x5220;&#x9664;&#x7684;&#x6587;&#x4EF6;</li>
<li>&#x6682;&#x5B58;&#x533A;&#x4E2D;&#x79FB;&#x52A8;/&#x91CD;&#x547D;&#x540D;&#x7684;&#x6587;&#x4EF6;</li>
</ul>
</li>
<li><p><code>git diff [args]</code>: &#x6BD4;&#x8F83;&#x4EE3;&#x7801;&#x7684;&#x5DEE;&#x5F02;.
&#x9ED8;&#x8BA4;&#x6BD4;&#x8F83;&#x6682;&#x5B58;&#x533A;&#x548C;&#x5DE5;&#x4F5C;&#x533A;&#x7684;&#x5DEE;&#x5F02;.</p>
<ul>
<li><code>git diff &lt;commit ID&gt; [commit ID 2]</code>: &#x6BD4;&#x8F83;&#x6307;&#x5B9A;&#x63D0;&#x4EA4;&#x4E4B;&#x95F4;&#x7684;&#x5DEE;&#x5F02;.
&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A; <code>commit ID 2</code>, &#x5219;&#x6BD4;&#x8F83;&#x6307;&#x5B9A;&#x63D0;&#x4EA4;&#x4E0E;&#x5DE5;&#x4F5C;&#x533A;&#x7684;&#x5DEE;&#x5F02;.</li>
<li><code>git diff --cached [commit ID]</code>: &#x6BD4;&#x8F83;&#x6682;&#x5B58;&#x533A;&#x548C;&#x76EE;&#x6807;&#x63D0;&#x4EA4;&#x7684;&#x5DEE;&#x5F02;.
&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A; <code>commit ID</code>, &#x5219;&#x9ED8;&#x8BA4;&#x548C;&#x6700;&#x8FD1;&#x4E00;&#x6B21;&#x63D0;&#x4EA4;&#x6BD4;&#x8F83;.</li>
</ul>
</li>
<li><code>git log</code>: &#x67E5;&#x770B;&#x5386;&#x53F2;&#x63D0;&#x4EA4;&#x8BB0;&#x5F55;</li>
<li><code>ls-files</code>: &#x67E5;&#x770B;&#x6682;&#x5B58;&#x533A;&#x8FFD;&#x8E2A;&#x7684;&#x6587;&#x4EF6;</li>
</ul>
<h2 id="&#x5206;&#x652F;&#x7BA1;&#x7406;">&#x5206;&#x652F;&#x7BA1;&#x7406;</h2>
<ul>
<li><p><code>git branch [branch name]</code>: &#x5217;&#x51FA;&#x6240;&#x6709;&#x672C;&#x5730;&#x5206;&#x652F;.</p>
<ul>
<li><code>branch name</code>: &#x521B;&#x5EFA;&#x540D;&#x4E3A; <code>branch name</code> &#x7684;&#x65B0;&#x5206;&#x652F;, &#x505C;&#x7559;&#x5728;&#x5F53;&#x524D;&#x5206;&#x652F;.</li>
</ul>
</li>
<li><p><code>git checkout [-b] &lt;branch&gt;</code>: &#x5207;&#x6362;&#x5230; <code>branch</code> &#x5206;&#x652F;.</p>
<ul>
<li><code>-b</code>: &#x521B;&#x5EFA;&#x65B0;&#x5206;&#x652F;&#xFF0C;&#x5E76;&#x5207;&#x6362;&#x5230;&#x8BE5;&#x5206;&#x652F;&#x4E2D;.</li>
</ul>
</li>
<li><p><code>git merge [branch]</code>: &#x5C06;&#x8FDC;&#x7A0B;&#x5206;&#x652F;&#x5408;&#x5E76;&#x5230;&#x5F53;&#x524D;&#x5206;&#x652F;.</p>
<ul>
<li><code>branch</code>: &#x5C06; <code>branch</code> &#x5206;&#x652F;&#x5408;&#x5E76;&#x5230;&#x5F53;&#x524D;&#x5206;&#x652F;.</li>
</ul>
</li>
</ul>
<footer class="page-footer"><span class="copyright"><a href="mailto:tanghaojin18@mails.ucas.ac.cn" target="_blank">&#x5510;&#x6D69;&#x664B;</a>&#xB7;&#x9AD8;&#x6CFD;&#x5B87;&#xB7;&#x9648;&#x7490; 2021<br><a href="http://www.beian.miit.gov.cn/" target="_blank">&#x4EAC;ICP&#x5907;20000818&#x53F7;-2</a></span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-07-11 16:37:52
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: 基本操作">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="本地与远程仓库的交互.html" class="navigation navigation-next " aria-label="Next page: 本地与远程仓库的交互">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"从本地建立仓库","level":"1.3.1","depth":2,"next":{"title":"本地与远程仓库的交互","level":"1.3.2","depth":2,"path":"基本操作/本地与远程仓库的交互.md","ref":"基本操作/本地与远程仓库的交互.md","articles":[]},"previous":{"title":"基本操作","level":"1.3","depth":1,"path":"基本操作/README.md","ref":"基本操作/README.md","articles":[{"title":"从本地建立仓库","level":"1.3.1","depth":2,"path":"基本操作/从本地建立仓库.md","ref":"基本操作/从本地建立仓库.md","articles":[]},{"title":"本地与远程仓库的交互","level":"1.3.2","depth":2,"path":"基本操作/本地与远程仓库的交互.md","ref":"基本操作/本地与远程仓库的交互.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["intopic-toc","-lunr","-search","search-pro","theme-comscore","tbfed-pagefooter","flexible-alerts"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"<a href=\"mailto:tanghaojin18@mails.ucas.ac.cn\">唐浩晋</a>·高泽宇·陈璐 2021","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"intopic-toc":{"isCollapsed":true,"isScrollspyActive":true,"label":"In this article","maxDepth":6,"mode":"nested","selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","visible":true},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"flexible-alerts":{"danger":{"className":"danger","icon":"fa fa-ban","label":"Attention"},"note":{"className":"info","icon":"fa fa-info-circle","label":"Note"},"style":"callout","tip":{"className":"tip","icon":"fa fa-lightbulb-o","label":"Tip"},"warning":{"className":"warning","icon":"fa fa-exclamation-triangle","label":"Warning"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"唐浩晋 <tanghaojin@outlook.com>; 陈璐; 高泽宇","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*"},"file":{"path":"基本操作/从本地建立仓库.md","mtime":"2021-07-11T08:37:52.286Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-07-18T10:09:23.538Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

